;
(function () {
  new Vue({
    el: '#report_contract',
    data: {
      quanxian: JSON.parse(localStorage.getItem('permissions')),
      pageCounts: [{
          'name': '10',
          'code': 10
        },
        {
          'name': '15',
          'code': 15
        },
        {
          'name': '20',
          'code': 20
        },
      ],
      currentPage: 1,
      totalPage: 0,
      totalCount: 0,
      limit: ['10'],

      projectList: [],
      selectedProId: '',
      selectedProName: '',
      projectIdSelect: ['#'],

      keyword: '',
      billDate: '',
      financialBeforeDate: '',
      financialAfterDate: '',

      rentStatus: [{
          'name': '全部',
          'code': '#'
        },
        {
          'name': '预定',
          'code': 'BI'
        },
        {
          'name': '已出租',
          'code': 'IR'
        },
        {
          'name': '即将履约',
          'code': 'IP'
        },
        {
          'name': '即将到期',
          'code': 'DU'
        },
        {
          'name': '自用',
          'code': 'OU'
        },
        {
          'name': '空置',
          'code': 'WA'
        },
      ],
      selectedRent: [],
      untilContracts: []
    },
    filters: {
      toZero: function (n) {
        return n < 10 ? '0' + n : '' + n
      },
      UTCdate: function (time) {
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
      formatNum: function (num) {
        return hlNumberUtil.formatNum(num)
      },
      nullundefinded(item) {
        if (!item) return '--';
        return item.join('、')
      }
    },
    computed: {

    },
    methods: {
      // 获取列表数据
      getData() {
        let data = {
          project_ids: this.selectedProId || '#',
          project_name: this.selectedProName || '#',
          keyword: this.keyword || '#',
          billing_date: this.billDate || '#',
          rent_state: this.selectedRent + '' || '#',
          page: this.currentPage,
          page_count: this.limit + '',
        }
        hlhttp.get({
          url: 'report/unit_contract',
          data: data,
          success: res => {
            this.totalPage = res.totalPage
            this.totalCount = res.totalCount
            this.untilContracts = res.untilContracts
          }
        })
      },
      // 获取所有项目
      getProject() {
        hlhttp.get({
          url: 'user/projects',
          success: (res) => {
            res = hlArrayUtil.removeRepeat(res, 'projectId')
            res.unshift({
              projectName: '所有项目',
              projectId: '#'
            })
            this.projectList = hlArrayUtil.replaceData(res, [{
              key: 'projectName',
              rKey: 'name'
            }, {
              key: 'projectId',
              rKey: 'code'
            }]);
          }
        })
      },
      // 选择某个项目
      getProjectItem(arr) {
        this.selectedProId = arr[0].code
        this.selectedProName = arr[0].name
      },
      // 查询
      search() {
        let data = {
          project_ids: this.selectedProId || '#',
          project_name: this.selectedProName || '#',
          keyword: this.keyword || '#',
          billing_date: this.billDate || '#',
          rent_state: this.selectedRent + '' || '#',
          page: this.currentPage,
          page_count: this.limit + '',
        }
        console.dir(data)
      },
      // 重置
      reset() {
        this.selectedProId = ''
        this.selectedProName = ''
        this.keyword = ''
        this.billDate = ''
        this.selectedRent = []
        this.currentPage = 1
        this.getData()
      },
      resetTabbar() {
        this.selectedRent = []
        this.currentPage = 1
        this.getData()
      },
      // 导出
      excl() {

      },
    },
    mounted() {
      this.getProject()
      this.getData()
      let y = new Date().getFullYear()
      let m = new Date().getMonth() + 1
      let d = new Date().getDate()

      this.financialBeforeDate = y - 1 + '-' + (m < 10 ? '0' + m : m) + '-' + d
      this.financialAfterDate = y + 1 + '-' + (m < 10 ? '0' + m : m) + '-' + d
      console.log(this.financialBeforeDate)
      console.log(this.financialAfterDate)
    }
  })

}())